<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
	<title>库区管理</title>
	<script src="${ctx}/static/detailPopover/areaGroupDetail.js" type="text/javascript"></script>
	<!-- <script>
		function areaGroupDetailAjax(id, name){
			var tempString = "";
			$.ajax({
				type : 'post',
				url : name +'/areaGroup/areaGroupDetail',
				data : 'id=' + id,
				dataType : 'json',
				success : function(data) {
					//alert("ok");
					$("#areaGroupDetailBody").html("");
					var areaGroup = data.areaGroup;
					tempString += "<tr><th>网点名称</th><th>网点编码</th><th>网点介绍</th></tr>";		
					tempString += "<tr><td>"+areaGroup.groupName+"</td><td>"+areaGroup.groupCode+"</td><td>"+areaGroup.groupIntro+"</td></tr>"
					$("#areaGroupDetailBody").append(tempString);
				},
				error : function() {
					alert("没有找到该网点的信息");
				}
			});
		}
	</script> -->
	<script type="text/javascript">
	var storage_id="";
	var storage_name="";
	var datatable_content;
	$(function(){
		initTable();
	});
	function initTable(){
		datatable_content = $("#contentTable").dataTable({
		   "bServerSide":true,
           "sAjaxSource":'${ctx}/v2/storage/page',
           "fnServerData": callback,
           "bFilter": false,
           "bSort": false,
           "bAutoWidth":false,
           "sZeroRecords": "查询无记录！",
           "bProcessing": true,
           "oLanguage": {
               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
            },
             "aoColumns":[
             	 {"mData": "name"},
             	 {"mData": "code"},
             	 {"mData": "num"},
             	 {"mData": "type"},
             	 {"mData": null},
             	 {"mData": null},
             ],
             "aoColumnDefs":[
             	 {"aTargets": [3],
	               "mRender": function (data, display, row) {
	               		return data == "simple" ?"简易库区" : "";
	            	}
	             },
             	 {"aTargets": [4],
	               "mRender": function (data, display, row) {
	               		return "<a href=\"#areaGroupDetail\" onclick=\"areaGroupDetailAjax('"+row.areaGroup.id+"', '${ctx}')\" data-toggle=\"modal\">"+row.areaGroup.groupName+"</a>";
	            	}
	             },
             	 {"aTargets": [5],
	               "mRender": function (data, display, row) {
	               		return "<a class=\"btn btn-danger\" href=\"${ctx}/v2/storage/delete/"+row.id+"\">删除</a>"+
	               		"<a href=\"#selextPrinterOne\" role=\"button\" data-toggle=\"modal\" class=\"btn btn-primary\" onclick=\"printerStock('"+row.code+"')\">打印库位</a>";
	            	}
	             },
             ],
		});
	}
	function callback( sSource, aoData, fnCallback ) {
	 aoData.push( { "name": "search_LIKE_name", "value": $("#search_LIKE_name").val()});  
		 //查询参数
	   $.ajax({ 
	       "type": "post",
	       "contentType": "application/json", 
	       "url": sSource,    
	       "dataType": "json",   
	       "data": JSON.stringify(aoData),
	       "success": fnCallback  
	   });    
	}
	
	function query(){
		datatable_content.fnDestroy();
		initTable();
	}		
		function createPartition(id,name)
		{
			storage_id = id;
			storage_name = name;
			$("#partition_code").val("");
			$("#partition_name").val("");
			$("#partition_remark").val("");
		}
		
		function addPartition() {
			var partition_code = $("#partition_code").val();
			var partition_name = $("#partition_name").val();
			var partition_remark = $("#partition_remark").val();
			$.ajax({
				type : 'post',
				url : '${ctx}/v2/storage/addPartition',
				data : 'storage_id=' + storage_id + '&partition_code=' + partition_code + '&partition_name=' + partition_name + '&partition_remark=' + partition_remark,
				dataType : 'json',
				success : function(data) {
					if (data.status == "1") {
						alert("创建成功");
					} else if (data.status == "0") {
						//alert("创建失败！");
					}
				},
				error : function() {
				}
			});
		}
		function printStockCode(printName, taskName,name) {
			LODOP = getLodop(document.getElementById('LODOP_OB'), document
					.getElementById('LODOP_EM'));
	      
			LODOP.PRINT_INIT(taskName);
			LODOP.SET_PRINT_PAGESIZE(1, 500, 318, "");
			
			LODOP.ADD_PRINT_BARCODE(25, 10, 180, 40, "128A", taskName);
			LODOP.SET_PRINT_STYLE("FontName","隶书");
	        LODOP.SET_PRINT_STYLE("FontSize",20);
			LODOP.ADD_PRINT_TEXT(65, 50, 200, 40, name);
			if (LODOP.SET_PRINTER_INDEXA(printName)) {
				LODOP.PRINT();
			}
		}
		function printerStock(code) {
			//var indexLength = getPrinterCount();
			//var tempString = "";
			//for ( var i = 0; i < indexLength; i++) {
			//	var name = getPrinterName(i);
			//	tempString += "<option value='"+name+"'>" + name + "</option>";
			//}
			$("#hiddenCode").val(code);
			$("#printerNumberOne").html("选择打印机：打印库区(" + code + ")库位");
			//$("#printerBodyOne").html(tempString);
			packFormPrinter("printerBodyOne");
		}
		
		function ajaxPrinterStock() {
			var code = $("#hiddenCode").val();
			$.ajax({
				type : 'post',
				url : '${ctx}/v2/storage/printStock',
				data : 'code=' + code,
				dataType : 'json',
				success : function(data) {
					if (data.status == "1") {
						var printName = $("#printerBodyOne").val();
						$.each(data.content, function(i) {
							printStockCode(printName, data.content[i].stock_code,data.content[i].stock_name);
						});
						alert("打印完毕！");
					} else if (data.status == "0") {
						alert("获取信息错误,打印失败！");
					}
	
				},
				error : function() {
					alert("获取信息错误,打印失败！");
				}
			});
		}
	</script>
</head>

<body>
	<c:if test="${not empty message}">
		<div id="message" class="alert alert-success"><button data-dismiss="alert" class="close">×</button>${message}</div>
	</c:if>
	<section class="content">
		<div class="row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
			<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
			<form class="form-search" action="?">
			 	<label>库区名称：</label>
			 	<input type="text" name="search_LIKE_name" id="search_LIKE_name" class="input-medium" value="${param.search_LIKE_name}" onkeydown='if(event.keyCode==13) {query(); return false;}'> 
			    <button type="button" class="btn btn-info" onclick="query()">搜索</button>
			    <a class="btn btn-info" href="${ctx}/v2/storage/create">创建库区</a>
		    </form>
	    </div>
	</div>
	</div>
	</div>
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>
					库区名
				</th>
				<th>
					库区编码
				</th>
				<th>
					库位数量
				</th>
				<th>
					库区类型
				</th>
				<th>
				所属服务网点
				</th>
				<th>
				管理
				</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	</div>
	</div>
	</div>
	</div>
	
	<div id="areaGroupDetail"  class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" role="dialog">
		<div class="modal-dialog" style="width: 60%;">
		<div class="modal-content">
		<div class="modal-header">
			<h3>网点详情</h3>
		</div>
		<div class="modal-body">
			<table id="areaGroupDetailBody" class="table table-striped table-bordered table-condensed"></table>
		</div>
		<div class="modal-footer">
			<button class="btn" data-dismiss="modal" aria-hidden="true">返回</button>
		</div>
		</div>
		</div>
	</div>
	<input type="hidden" id="hiddenCode" value="">
	<input type="hidden" id="hiddenName" value="">
	<div class="modal fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
			aria-hidden="true" id="selextPrinterOne">
		<div class="modal-dialog" style="width: 1000">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">
					×
				</button>
				<h3 id="printerNumberOne">
					选择打印机
				</h3>
			</div>
			<div class="modal-body">
				<select id="printerBodyOne" name="printerBody">
				</select>
			</div>
			<div class="modal-footer">

				<button class="btn" data-dismiss="modal" aria-hidden="true"
					id="printer" onclick="ajaxPrinterStock()">
					开始打印
				</button>

				<button class="btn" data-dismiss="modal" aria-hidden="true">
					Close
				</button>
			</div>
		</div>
</section>
</body>
</html>
